package com.weiqiao.mall.rest;

import com.weiqiao.mall.domain.StrategyEntity;
import com.weiqiao.mall.service.IStrategyService;
import com.weiqiao.mall.service.vo.StrategyVO;
import com.weiqiao.utils.PageUtil;
import com.weiqiao.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class StrategyController {
    /**
     * 余额提现业务层
     */
    @Autowired
    private IStrategyService strategyservice;

    @GetMapping("/strategy-list")
    public ResponseEntity strategyList(StrategyVO vo){
        List<StrategyEntity> list = strategyservice.strategyList(vo);
        int total = strategyservice.countStrategy(vo);
        return new ResponseEntity(PageUtil.toPage(list,total), HttpStatus.OK);
    }

    /**
     * 获取攻略详情
     * @param strategy_id
     * @return
     */
    @GetMapping("/get-strategy-info/{strategy_id}")
    public ResponseEntity getStrategyInfo(@PathVariable String strategy_id){
        int companyId = SecurityUtils.getCompanyId();
        StrategyEntity entity = strategyservice.strategyInfo(companyId, strategy_id);
        return new ResponseEntity(entity, HttpStatus.OK);
    }

    @PostMapping("/update-strategy")
    public ResponseEntity updateStrategy(StrategyVO vo){
        return new ResponseEntity(strategyservice.updateStrategy(vo),HttpStatus.OK);
    }

    @PostMapping("/insert-strategy")
    public ResponseEntity insertStrategy(StrategyEntity vo){
        return new ResponseEntity(strategyservice.insertStrategy(vo),HttpStatus.OK);
    }

    @PostMapping("/delete-strategy")
    public ResponseEntity deleteStrategy(StrategyVO vo){
        return new ResponseEntity(strategyservice.deleteStrategy(vo),HttpStatus.OK);
    }

}
